<template>
<div>
  <div class="map" style="border: 0; height:calc(100vh - 64px); width: 100%">
    <iframe
      v-if="loaded"
      id="parentId"
      :src="frameUrl + code + '%20' + token"
      style="border: 0; height: 100%; width: 100%"
    />
  </div>
</div>
</template>

<script>
import Cookies from 'js-cookie'
import { getUserByToken } from '@/api/login'
export default {
  data() {
    return{
      frameUrl: null,
      code: '',
      token: '',
      loaded:false
    }
  },
  async mounted() {
    await this.getUserByToken();
    await this.getFrameUrl();
  },
  methods: {
    getFrameUrl() {
      switch(this.$route.name) {
        case "hyglIndex":
          this.frameUrl = process.env.VUE_APP_MMS_HY_URL;
          this.loaded = true;
          break;
        case "ytglIndex":
          this.frameUrl = process.env.VUE_APP_MMS_YT_URL;
          this.loaded = true;
          break;
        default:
          return null;
      }
    },
    getUserByToken() {
      let req = {
        token: Cookies.get('gisinfo')
      }
      getUserByToken(req)
        .then(res => {
          let { system, token } = res.data.result;
          this.code = system;
          this.token = token;
        })
    }
  }

}
</script>

